#ifndef APPLICATIONS_APP_MAIN_H_
#define APPLICATIONS_APP_MAIN_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

/**
 * @brief 模块使用开关，不使时则注释
 */
//#define APP_USING_MPU6050
//#define APP_USING_LCD
//#define APP_USING_NBIOT
#define APP_USING_L610 /**< 是否使用4G模块 */
#define APP_USING_MQTT /** 是否使用MQTT */

#define APP_MQTT_HOSTNAME               "cloud1.jswyll.com"
#define APP_MQTT_PORT                   "1883"
#define APP_MQTT_CLIENTID               "test"
#define APP_MQTT_USERNAME               "523675"
#define APP_MQTT_PASSWROD               "test"
#define APP_MQTT_PUBLISH_TOPIC          "$sys/"APP_MQTT_USERNAME"/"APP_MQTT_CLIENTID"/dp/post/json"

/** 温湿度传感器引脚 */
#define DHT11_PIN                       GET_PIN(B, 3)

/**
 * 电机
 */
#define MOTOR_DEV_NAME                  "pwm3"              /* PWM设备名称 */
#define MOTOR_DEV_CHANNEL1              1                   /* PWM通道 */
#define MOTOR_DEV_CHANNEL2              2                   /* PWM通道 */
#define AIN1_PIN                        GET_PIN(A, 4)
#define AIN2_PIN                        GET_PIN(A, 5)
#define BIN1_PIN                        GET_PIN(B, 6)
#define BIN2_PIN                        GET_PIN(B, 7)

/**
 * 舵机
 */
#define STEER_UD_HTIM                    htim13
#define STEER_UD_CHANNEL                 TIM_CHANNEL_1
#define STEER_LR_HTIM                    htim14
#define STEER_LR_CHANNEL                 TIM_CHANNEL_1

/**
 * 按键
 */
#define KEY0_PIN                        GET_PIN(E, 4)
#define KEY1_PIN                        GET_PIN(E, 3)
#define KEY2_PIN                        GET_PIN(E, 2)

/**
 * LED
 */
#define LED1_PIN                        GET_PIN(A, 1)
#define LED_ON                          PIN_LOW
#define LED_OFF                         PIN_HIGH

#define SPRAY_PIN                       GET_PIN(B, 8)

/**
 * 超声波
 */
#define SR041_TRIG_PIN                  GET_PIN(C, 0)
#define SR041_ECHO_PIN                  GET_PIN(C, 1)
#define SR042_TRIG_PIN                  GET_PIN(C, 2)
#define SR042_ECHO_PIN                  GET_PIN(C, 3)
#define SR043_TRIG_PIN                  GET_PIN(C, 4)
#define SR043_ECHO_PIN                  GET_PIN(C, 5)
#define SR044_TRIG_PIN                  GET_PIN(C, 0)
#define SR044_ECHO_PIN                  GET_PIN(C, 1)

/**
 * 串口
 */
#define UART1_DEV_NAME                  "uart1"
#define NBIOT_DEV_NAME                  "uart2"
#define L610_DEV_NAME                   "uart2"             /**< 4G模块 */
#define UART3_DEV_NAME                  "uart3"
#define UART6_DEV_NAME                  "uart4"

/**
 * IIC总线
 */
#define MPU6050_I2C_BUS_NAME            "i2c1"              /**< 陀螺仪MPU6050 */
#define BH1750_I2C_BUS_NAME             "i2c1"              /**< 光强传感器BH1750 */
#define SGP30_I2C_BUS_NAME              "i2c2"              /**< 气体传感器SGP30 */

/**
 * 线程优先级，越小优先级越高
 */
#define PRIO_DISTANCE                   (RT_MAIN_THREAD_PRIORITY - 4)
#define PRIO_NBIOT                      (RT_MAIN_THREAD_PRIORITY - 3)
#define PRIO_MPU6050                    (RT_MAIN_THREAD_PRIORITY - 2)
#define PRIO_UPLOAD                     (RT_MAIN_THREAD_PRIORITY - 1)
#define PRIO_KEY_SCAN                   (RT_MAIN_THREAD_PRIORITY + 1)
#define PRIO_REMOTE_CONTROL             (RT_MAIN_THREAD_PRIORITY + 2)
#define PRIO_UPLOAD_RECV                (RT_MAIN_THREAD_PRIORITY + 3)
#define PRIO_BEEP                       (RT_MAIN_THREAD_PRIORITY + 5)

/**
 * 蜂鸣器
 */
#define BEEP_PIN                        GET_PIN(D, 7)
#define BEEP_ON                         PIN_LOW
#define BEEP_OFF                        PIN_HIGH

/**
 * 事件
 */
#define EVENT_PRESS_KEY0                (1 << 0)            /**< 按键0按下 */
#define EVENT_PRESS_KEY1                (1 << 1)            /**< 按键1按下 */
#define EVENT_PRESS_KEY2                (1 << 2)            /**< 按键2按下 */
#define EVENT_MPU6050_INIT              (1 << 3)            /**< MPU6050初始化成功 */
#define EVENT_REQ_BEEP                  (1 << 4)            /**< 请求蜂鸣器响 */
#define EVENT_UPLOAD_DHT                (1 << 5)            /**< 请求上传温湿度 */
#define EVENT_UPLOAD_DISEASE            (1 << 6)            /**< 请求上传病虫害类型 */
#define EVENT_UPLOAD_LIGHT              (1 << 7)            /**< 请求上传光照强度 */
#define EVENT_UPLOAD_CO2VOC             (1 << 8)            /**< 请求上传气体浓度 */
#define EVENT_UPLOAD_YAW                (1 << 9)            /**< 请求上传偏航角 */
#define EVENT_UPLOAD_HUMIDITY2          (1 << 10)           /**< 请求上传土壤温湿度 */
#define EVENT_UPLOAD_THING              (1 << 11)           /**< 请求上传xxx */
#define EVENT_NBIOT_NET_READY           (1 << 12)           /**< NBIOT已联网 */
#define EVENT_NBIOT_MQTT_READY          (1 << 13)           /**< NBIOT已连接MQTT */
#define EVENT_NBIOT_PUBLISHED           (1 << 14)           /**< NBIOT发布消息成功 */
#define EVENT_L610_NET_READY            (1 << 15)           /**< 4G模块已联网 */
#define EVENT_L610_MQTT_READY           (1 << 16)           /**< 4G模块已连接MQTT */
#define EVENT_L610_PUBLISHED            (1 << 17)           /**< 4G模块发布消息成功 */
#define EVENT_REMOTE_CONTROL            (1 << 18)           /**< 远程控制 */

#define delay_ms                        rt_thread_mdelay

extern rt_event_t s_event;

#endif /* APPLICATIONS_APP_MAIN_H_ */
